import { onActivated, onMounted, watch, ref } from "vue";
import type { WatchSource } from "vue";



export function useMounedExection<T = any>(deps: WatchSource & Dict<unknown>, callback: (v?: T) => any) {
  const mountd = ref(false);

  const mountRunner = async () => {
    if (mountd.value) {
      return;
    }
    mountd.value = true;
    await callback();
    mountd.value = false;
  };


  onActivated(mountRunner);
  onMounted(mountRunner);

  return watch(
    () => deps,
    mountRunner,
    { deep: true, immediate: false }
  );
}

